package com.example.baomidou.controller;

import com.example.baomidou.entity.SnowOperateLog;
import com.example.baomidou.service.ISnowOperateLogService;
import com.example.baomidou.vo.OperateRecordReq;
import com.example.baomidou.vo.PageDto;
import com.example.baomidou.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/operate")
public class OperateLogController {
 
    @Resource
    private ISnowOperateLogService operateLogService;
//
    @PostMapping("/insert")
    public Result insert(@RequestBody OperateRecordReq request) {
        SnowOperateLog operateLog = new SnowOperateLog();
        operateLog.setOperator(request.getOperator());
        operateLog.setOperateTime(request.getOperateTimeStart());
        operateLog.setOperateType(Integer.valueOf(request.getOperateType()));
        operateLogService.save(operateLog);
        return Result.success();
    }
//
//    @PostMapping("/insert-batch")
//    public Result insertBatch(@RequestBody OperateRecordReq request) {
//        LocalDateTime dateTime = LocalDateTime.now();
//        List<SnowOperateLog> list = new ArrayList<>();
//        for (int i = 0; i < 10; i++) {
//            SnowOperateLog operateLog = new SnowOperateLog();
//            operateLog.setBatchNo(String.valueOf(System.currentTimeMillis()));
//            operateLog.setOperator("liudehua" + i);
//            operateLog.setOperateType(1);
//            operateLog.setOperateTime(dateTime);
//            list.add(operateLog);
//        }
//        operateLogService.saveBatch(list);
//        return Result.success();
//    }
//
//    @GetMapping("/delete")
//    public Result<List<SnowOperateLog>> deleteById(@RequestParam(value = "id") String id) {
//        operateLogService.deleteById(id);
//        return Result.success();
//    }
//
//    @PostMapping("/update-by-name")
//    public Result updateByOperator(@RequestBody OperateRecordReq request) {
//        operateLogService.updateByOperator(request.getOperator());
//        return Result.success();
//    }
//
    @PostMapping("/queryList")
    public Result<PageDto<SnowOperateLog>> queryList(@RequestBody OperateRecordReq request) {
        return operateLogService.queryList(request);
    }
//
//    @PostMapping("/query-by-name")
//    public Result<List<SnowOperateLog>> selectAllByOperator(@RequestBody OperateRecordReq request) {
//        List<SnowOperateLog> snowOperateLogs = operateLogService.selectAllByOperator(request.getOperator());
//        return Result.success(snowOperateLogs);
//    }
}